from django.db import models
from enum import Enum
from apps.user.models import User
from deps.voidsdk.pytoolset.enum import Enum

# class UserRelationStatus(Enum):
#     attention = "关注"
#     black = "拉黑"


# UserRelationStatus = (
#     (1, "关注"),
#     (2, "拉黑"),
# )

UserRelationStatus = Enum(((
    (1, "ATTENTION",  "关注"),
    (2,  "BLACK",  "拉黑"),
 )))


class News(models.Model):
    """
    动态
    """
    content = models.CharField("内容", max_length=300, blank=True, default="")
    user = models.ForeignKey(User, verbose_name=u'用户', related_name='new_user')
    up = models.ManyToManyField(User)
    image = models.TextField("图片", blank=True, default="")
    video = models.TextField("视频", blank=True, default="")
    position = models.CharField("位置", max_length=50, blank=True, default="")
    longitude = models.FloatField("经度", blank=True, default=0)
    latitude = models.FloatField("纬度", blank=True, default=0)
    created = models.DateTimeField(u'发布时间', auto_now_add=True)

    @property
    def up_cnt(self):  # 点赞
        return self.up.all().count()

    def __str__(self):
        return self.content

    class Meta:
        verbose_name = "动态"
        verbose_name_plural = verbose_name


class Comments(models.Model):
    """
    评论
    """
    content = models.CharField("内容", max_length=300, blank=True, default="")
    user = models.ForeignKey(User, verbose_name=u'用户', related_name='comment_user')
    new = models.ForeignKey(News, verbose_name=u'动态', related_name='comment_new')
    created = models.DateTimeField(u'发布时间', auto_now_add=True)

    def __str__(self):
        return self.content

    class Meta:
        verbose_name = "评论"
        verbose_name_plural = verbose_name


class UserRelation(models.Model):
    """
    用户关系
    """
    user = models.ForeignKey(User, verbose_name=u'用户', related_name='relation_user')
    object_user = models.ForeignKey(User, verbose_name=u'对象', related_name='relation_object_user')
    relation = models.IntegerField('关系', choices=UserRelationStatus.choice_tuples())

    def __str__(self):
        return self.user.nickname

    class Meta:
        verbose_name = "用户关系"
        verbose_name_plural = verbose_name
